package com.bdsoft.actions.RoleManage.Controller;

import com.bdsoft.actions.AcUrls;
import com.bdsoft.actions.RoleManage.DTO.RoleDTO;
import com.bdsoft.actions.RoleManage.Service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(AcUrls.RoleManage.roleManageUrl)
@Tag(name = "角色相关接口")
public class RoleController {

    @Autowired
    RoleService roleService;

    @Operation(summary = "获得角色分页列表")
    @PostMapping(AcUrls.RoleManage.getRoleList)
    public ResponseEntity getRoleList(@RequestParam int pageNum, @RequestParam int pageSize,
                                      @RequestParam(required = false) String id,
                                      @RequestParam(required = false) String name) {
        return ResponseEntity.ok(roleService.getRoleList(pageNum, pageSize, id, name));
    }
    @Operation(summary = "根据角色id获得已分配菜单")
    @PostMapping(AcUrls.RoleManage.getMenuList)
    public ResponseEntity getMenuList(String roleId) {
        return ResponseEntity.ok(roleService.getMenuList(roleId));
    }

    @Operation(summary = "保存/修改角色")
    @PostMapping(AcUrls.RoleManage.saveOrUpdateRole)
    public Map<String,Object> saveOrUpdateRole(@RequestBody RoleDTO roleDTO) {
        return roleService.saveOrUpdateRole(roleDTO);
    }

    @Operation(summary = "删除角色")
    @PostMapping(AcUrls.RoleManage.deleteRole)
    public Map<String,Object> deleteRoleById(@RequestParam String id) {
        return roleService.deleteRoleById(id);
    }
} 